import sys

from PySide6.QtWidgets import QApplication, QWidget, QPushButton, QFontDialog, QTextEdit, QVBoxLayout, QColorDialog


class MainWindow(QWidget):
    def __init__(self):
        super().__init__()

        self.editText = QTextEdit()
        self.fontBtn = QPushButton('选择字体')
        self.fontBtn.clicked.connect(self.change_font)
        self.colorBtn = QPushButton('选择颜色')
        self.colorBtn.clicked.connect(self.change_color)

        self.mainLayout = QVBoxLayout()
        self.mainLayout.addWidget(self.editText)
        self.mainLayout.addWidget(self.fontBtn)
        self.mainLayout.addWidget(self.colorBtn)
        self.setLayout(self.mainLayout)

    def change_font(self):
        ok, font = QFontDialog.getFont(self.editText.font(), self)
        if not ok: return
        self.editText.setFont(font)

    def change_color(self):
        color = QColorDialog.getColor()
        self.editText.setTextColor(color)


if __name__ == '__main__':
    app = QApplication([])
    window = MainWindow()
    window.show()
    app.exec()
